{extend name="base"}
{block name="style"}
<!-- 这里允许在引入一些样式头部 -->
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="{:_static()}/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all" />
<link rel="stylesheet" href="{:_static()}/css/user.css" media="all" />
<link rel="stylesheet" href="{:_static()}/css/common.css" media="all" />

{/block}

{block name="main"}
<style type="text/css">
	.ws-main{padding: 15px;}
	a:hover{color: inherit !important;}
	label{box-sizing: content-box;}
</style>

	<div class="childrenBody">
	
	<form class="layui-form changePwd">
		<div style="margin:0 0 15px 110px;color:#f00;">请输入正确的旧密码，新密码必须两次输入一致才能提交</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-block">
		    	<input type="text" value="{$user.login_name}" disabled class="layui-input layui-disabled">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">旧密码</label>
		    <div class="layui-input-block">
		    	<input type="password" name="pwd" value="" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">新密码</label>
		    <div class="layui-input-block">
		    	<input type="password" name="pwd1" value="" placeholder="请输入新密码" lay-verify="required|newPwd" id="oldPwd" class="layui-input pwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">确认密码</label>
		    <div class="layui-input-block">
		    	<input type="password" name="pwd2" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd">
		    </div>
		</div>
		<div class="layui-form-item">
		    <div class="layui-input-block">
		    	<button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	</div>

<script type="text/javascript" src="{:_static()}/layui/layui.js"></script>
<script type="text/babel" src="{:_static()}/js/common.js"></script>
<script type="text/babel" type="text/javascript">
// var areaData = address;
var $form;
var form;
var $;
layui.config({
	base : "js/"
}).use(['form','layer','laydate'],function(){
	form = layui.form();
	var layer = parent.layer === undefined ? layui.layer : parent.layer;
		$ = layui.jquery;
		$form = $('form');
		laydate = layui.laydate;
    //     loadProvince(); //加载省信息

    // layui.upload({
    // 	url : "../../json/userface.json",
    // 	success: function(res){
    // 		var num = parseInt(4*Math.random());  //生成0-4的随机数
    // 		//随机显示一个头像信息
	   //  	userFace.src = res.data[num].src;
	   //  	window.sessionStorage.setItem('userFace',res.data[num].src);
	   //  }
    // });

    //添加验证规则
    form.verify({
        // oldPwd : function(value, item){
        //     if(value != "123456"){
        //         return "密码错误，请重新输入！";
        //     }
        // },
        newPwd : function(value, item){
            if(value.length < 6){
                return "密码长度不能小于6位";
            }
        },
        confirmPwd : function(value, item){
            if(!new RegExp($("#oldPwd").val()).test(value)){
                return "两次输入密码不一致，请重新输入！";
            }
        }
    })

    // //判断是否修改过用户信息，如果修改过则填充修改后的信息
    // if(window.sessionStorage.getItem('userInfo')){
    //     var userInfo = JSON.parse(window.sessionStorage.getItem('userInfo'));
    //     var citys;
    //     $(".realName").val(userInfo.realName); //用户名
    //     $(".userSex input[value="+userInfo.sex+"]").attr("checked","checked"); //性别
    //     $(".userPhone").val(userInfo.userPhone); //手机号
    //     $(".userBirthday").val(userInfo.userBirthday); //出生年月
    //     $(".userAddress select[name='province']").val(userInfo.province); //省
    //     //填充省份信息，同时调取市级信息列表
    //     var value = userInfo.province;
    //     var d = value.split('_');
    //     var code = d[0];
    //     var count = d[1];
    //     var index = d[2];
    //     if (count > 0) {
    //         loadCity(areaData[index].mallCityList);
    //         citys = areaData[index].mallCityList
    //     } else {
    //         $form.find('select[name=city]').attr("disabled","disabled");
    //     }
    //     $(".userAddress select[name='city']").val(userInfo.city); //市
    //     //填充市级信息，同时调取区县信息列表
    //     var value = userInfo.city;
    //     var d = value.split('_');
    //     var code = d[0];
    //     var count = d[1];
    //     var index = d[2];
    //     if (count > 0) {
    //         loadArea(citys[index].mallAreaList);
    //     } else {
    //         $form.find('select[name=area]').attr("disabled","disabled");
    //     }
    //     $(".userAddress select[name='area']").val(userInfo.area); //区
    //     for(key in userInfo){
    //         if(key.indexOf("like") != -1){
    //             $(".userHobby input[name='"+key+"']").attr("checked","checked");
    //         }
    //     }
    //     $(".userEmail").val(userInfo.userEmail); //用户邮箱
    //     $(".myself").val(userInfo.myself); //自我评价
    //     form.render();
    // }

    // //判断是否修改过头像，如果修改过则显示修改后的头像，否则显示默认头像
    // if(window.sessionStorage.getItem('userFace')){
    // 	$("#userFace").attr("src",window.sessionStorage.getItem('userFace'));
    // }else{
    // 	$("#userFace").attr("src","../../images/face.jpg");
    // }

    // //提交个人资料
    // form.on("submit(changeUser)",function(data){
    // 	var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
    //     //将填写的用户信息存到session以便下次调取
    //     var key,userInfoHtml = '';
    //     userInfoHtml = {
    //         'realName' : $(".realName").val(),
    //         'sex' : data.field.sex,
    //         'userPhone' : $(".userPhone").val(),
    //         'userBirthday' : $(".userBirthday").val(),
    //         'province' : data.field.province,
    //         'city' : data.field.city,
    //         'area' : data.field.area,
    //         'userEmail' : $(".userEmail").val(),
    //         'myself' : $(".myself").val()
    //     };
    //     for(key in data.field){
    //         if(key.indexOf("like") != -1){
    //             userInfoHtml[key] = "on";
    //         }
    //     }
    //     window.sessionStorage.setItem("userInfo",JSON.stringify(userInfoHtml));
    //     setTimeout(function(){
    //         layer.close(index);
    //         layer.msg("提交成功！");
    //     },2000);
    // 	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    // })

    //修改密码
    form.on("submit(changePwd)",function(data){
        console.log(data.field);// 输出所有的表单数据
        //loading层
        var index2 = layer.load(1);
        // ajax提交添加
        $.ajax({
            url:'{:url("member/Usercenter/updpwd")}',
            type:'POST',
            data:data.field,
            dataType:'json',
            success:function(data){
                console.log(data)
                // 关闭loading
                layer.close(index2);
                // 根据返回结果提示操作是否成功
                if (data.code == 1) {
                    // 修改成功
                    // 关闭输入弹窗
                    // layer.close(index);
                    layer.msg('修改成功');

                    if (data.wait != '') {
                        ttime = data.wait*1000;
                    }
                    else{
                        ttime = 2000;
                    }
                    // 刷新当前页
                    window.setTimeout("window.location.reload()",ttime);
                }
                else{
                    // 修改失败
                    layer.msg(data.msg);
                }
            }
        });
    	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    })

})

/*//加载省数据
function loadProvince() {
    var proHtml = '';
    for (var i = 0; i < areaData.length; i++) {
        proHtml += '<option value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i + '">' + areaData[i].provinceName + '</option>';
    }
    //初始化省数据
    $form.find('select[name=province]').append(proHtml);
    form.render();
    form.on('select(province)', function(data) {
        $form.find('select[name=area]').html('<option value="">请选择县/区</option>');
        var value = data.value;
        var d = value.split('_');
        var code = d[0];
        var count = d[1];
        var index = d[2];
        if (count > 0) {
            loadCity(areaData[index].mallCityList);
        } else {
            $form.find('select[name=city]').attr("disabled","disabled");
        }
    });
}
//加载市数据
function loadCity(citys) {
    var cityHtml = '<option value="">请选择市</option>';
    for (var i = 0; i < citys.length; i++) {
        cityHtml += '<option value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i + '">' + citys[i].cityName + '</option>';
    }
    $form.find('select[name=city]').html(cityHtml).removeAttr("disabled");
    form.render();
    form.on('select(city)', function(data) {
        var value = data.value;
        var d = value.split('_');
        var code = d[0];
        var count = d[1];
        var index = d[2];
        if (count > 0) {
            loadArea(citys[index].mallAreaList);
        } else {
            $form.find('select[name=area]').attr("disabled","disabled");
        }
    });
}
//加载县/区数据
function loadArea(areas) {
    var areaHtml = '<option value="">请选择县/区</option>';
    for (var i = 0; i < areas.length; i++) {
        areaHtml += '<option value="' + areas[i].areaCode + '">' + areas[i].areaName + '</option>';
    }
    $form.find('select[name=area]').html(areaHtml).removeAttr("disabled");
    form.render();
    form.on('select(area)', function(data) {});
}*/
</script>
{/block}